home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 419 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.7 KB

  1. Path: solon.com!not-for-mail
  2. From: genew@mindlink.bc.ca (Gene Wirchenko)
  3. Newsgroups: comp.std.c,comp.lang.c.moderated
  4. Subject: Re: Integral promotion.
  5. Date: 17 Feb 1996 11:56:29 -0600
  6. Organization: MIND LINK! - British Columbia, Canada
  7. Sender: clc@solutions.solon.com
  8. Approved: clc@solutions.solon.com
  9. Message-ID: <4g54sd$alc@solutions.solon.com>
  10. References: <4fstj7$2l6@solutions.solon.com> <4fvk8c$eq8@solutions.solon.com> <4g174t$mq7@solutions.solon.com>
  11. NNTP-Posting-Host: solutions.solon.com
  12. X-Newsreader: Forte Free Agent 1.0.82
  13.  
  14. tada@athena.mit.edu (Michael J Zehr) wrote:
  15.  
  16. [snip]
  17.  
  18. >So while 
  19.  
  20. >x1 and x2 are shorts and remain shorts regardless of how the compiler
  21. >sees fit to pass them to the "test" function, in the expression "x1 +
  22. >x2" there values are converted to ints.  Thus the type of "x1 + x2" is
  23. >an int and it is *this* that is being converted to a short during the
  24. >assignment to result.
  25.  
  26. >The original poster was mostly right in the last sentence -- the values
  27. >of short variables in an expression are convert to int if an int can
  28. >hold all possible values, otherwise converted to an unsigned int.  It is
  29. >neither the arguments nor the parameters that are being converted.
  30.  
  31.      To me, this means that many arithmetic operators can not be done
  32. on short variables without conversion if int is bigger than short.  Is
  33. this what you meant?
  34.  
  35.      To elaborate, addition could result in a short overflow, but not
  36. int if int is bigger, so it'll be converted.  Similar statements can
  37. be made for subtraction, multiplication, division, and probably
  38. others.
  39.  
  40. >-michael j zehr
  41.  
  42. Sincerely,
  43.  
  44. Gene Wirchenko
  45.  
  46. C Pronunciation Guide:
  47.      y=x++;     "wye equals ex plus plus semicolon"
  48.      x=x++;     "ex equals ex doublecross semicolon"
  49.